﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class SelectSideFittingForm : System.Windows.Forms.Form
	{
		public SelectSideFittingForm(string lateralStyle, bool pointSelect, string filePath)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			if (pointSelect)
			{
				this.btnSide.Image = Image.FromFile(filePath + "\\侧连接_点选.png");
			}
			base.Icon = Resource.YArchitechIcon;
			this.connStyle = lateralStyle;
		}

		private void SelectSideFittingForm_Load(object sender, EventArgs e)
		{
			this.ductConn = this.cdm.GetDuctConnStyle(this.connStyle);
			Button buttonByConnStyle = this.cdm.GetButtonByConnStyle(this.ductConn, this.groupBox1);
			if (buttonByConnStyle != null)
			{
				this.cdm.SelectButton(buttonByConnStyle);
			}
		}

		private void btn_Click(object sender, EventArgs e)
		{
			System.Drawing.Color backColor = this.groupBox1.BackColor;
			Button button = sender as Button;
			if (button == null)
			{
				return;
			}
			if (this.cdm != null)
			{
				this.cdm = new ConnectDuctManage();
			}
			this.cdm.ChangeButtnBackColor(this.groupBox1, button);
			this.ductConn = this.cdm.GetConnectStyle(button);
		}

		private void btnBack_MouseDown(object sender, MouseEventArgs e)
		{
			if (e.Clicks == 2)
			{
				base.Close();
			}
		}

		private void SelectSideFittingForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			new HVACUserSetting().WriteDuctConnLateralStyle(this.ductConn.ToString());
		}

		private void SelectSideFittingForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
		{
			if (keyData == Keys.Escape)
			{
				base.Close();
				return true;
			}
			return base.ProcessCmdKey(ref msg, keyData);
		}

		private string connStyle = "";

		public ConnectDuctStyle ductConn = ConnectDuctStyle.Empty;

		private ConnectDuctManage cdm = new ConnectDuctManage();
	}
}
